{- Reliability.orc -- Orc program Reliability
 - 
 - $Id$
 - 
 - Created by akattepu on Sep 5, 2012 2:24:36 PM
 -}

def bestQoS(comparer, publisher) = head(sortBy(comparer, publisher))

type Level= String
def Level() = signal
def ReliabilityValue() = if (URandom() :> 0.5) then "in_operation" else "failure"
 
-- Types and Definitions for Security
type Reliability = String
def class Reliability(unit) = 
  def QoS(String,String) :: String
  def QoS(sitex,reliability) =
    val k = Ref(0) 
    signal >>(k? >> Dictionary() >s> s.sitename := sitex >> s.sec := reliability >> s.sec?)
  
  def QoSOplus(String,String) :: String
  def QoSOplus(sl1,sl2) = Ift(sl1="in_operation" && sl2="in_operation") >> "in_operation" 
                          |  Iff(sl1="in_operation" && sl2="in_operation") >> "failure"
  
  def QoSCompare(String,String) :: String
  def QoSCompare(sl1,sl2) = (sl1 = "in_operation" && sl2="failure") 
  
  def QoSCompete(String,String) :: String
  def QoSCompete(sl1,sl2) = bestQoS(QoSCompare,[sl1,sl2])
  
  stop  
  